package cn.itsource.blog.controller;

import cn.itsource.blog.anno.PreAuthorize;
import cn.itsource.blog.domain.Role;
import cn.itsource.blog.query.ArticleQuery;
import cn.itsource.blog.service.IRoleService;
import cn.itsource.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @PatchMapping("/list")
    public JsonResult list() {
        try{
            return JsonResult.success(roleService.getAll());
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @PatchMapping
    public JsonResult queryPage(@RequestBody ArticleQuery employeeQuery) {
        try{
            return JsonResult.success(roleService.pageInfo(employeeQuery));
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @PutMapping
    @PreAuthorize(name = "文章新增",sn = "employee:save",descs = "就是测试一把")
    public JsonResult save(@RequestBody Role employee) {
        try{
            roleService.save(employee);
            return JsonResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

}
